package vn.vttu.baocaocuoiki.NguyenHoangTrung;

import vn.vttu.baocaocuoiki.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

public class DoiMaunenActivity extends Activity {

	int color;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_doi_maunen);
        //xoay man hinh se tra ve mau sac da chon
        if(savedInstanceState != null)
        {
        	color = savedInstanceState.getInt("colored");
        	LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        	layout.setBackgroundColor(color);
        }
    }
    public void chonMau(View view) {
		// TODO Auto-generated method stub
    	Intent intent = new Intent(getApplicationContext(),DoiMaunenActivity.class);
    	startActivityForResult(intent,100);
	}
    	protected void onActivityResult(int requestCode, int resultCode, Intent data )
    	{
    		//xu ly thong diep tu activity khac gui den
    		switch (requestCode)
    		{
    		case 100:
    			if(resultCode == RESULT_OK){
    				Bundle bundle = data.getExtras();
    				color = bundle.getInt("colored");
    				LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
    	        	layout.setBackgroundColor(color);
    	        	
    			}
    		}
    	}
    	@Override
    	protected void onSaveInstanceState(Bundle outState) {
    		// TODO Auto-generated method stub
    		outState.putInt("colored", color);
    		super.onSaveInstanceState(outState);
    	}
    }